//
//  LYFSearchViewController.m
//  段子手
//
//  Created by dllo on 16/3/18.
//  Copyright © 2016年 JokesTeam. All rights reserved.
//

#import "LYFSearchViewController.h"

@interface LYFSearchViewController ()<UISearchBarDelegate>

@property (nonatomic, retain) UISearchBar *searchBar;/**< 顶部搜索框 */
@property (nonatomic, retain) UIBarButtonItem *backButton;/**< 左上角返回按钮 */
@property (nonatomic, retain) UIImageView *placeHolderImg;/**< 搜索页空白时候的占位图 */
@property (nonatomic, retain) UILabel *placeHolderLabel;/**< 占位图下面的文字 */

@end

@implementation LYFSearchViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)dealloc {
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];

    // 隐藏返回按钮
    [self.navigationItem setHidesBackButton:YES];
    
    [self createSearchBar];
    [self createImg];
}

/** 创建searchbar */
- (void)createSearchBar {
    self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(50, 0, SCREEN_WIDTH - 100, 50)];
    _searchBar.barStyle = UIBarStyleDefault;
    _searchBar.placeholder = @"动动麒麟臂，搜索更多内容~";
    [_searchBar setImage:[UIImage imageNamed:@"sousuo"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
    

    [self.navigationController.navigationBar addSubview:_searchBar];
    _searchBar.delegate = self;
    

    self.backButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"fanhui"] style:0 target:self action:@selector(backButtonAction:)];
    self.navigationItem.leftBarButtonItem = _backButton;
    }

/** 创建搜索背景占位图 */
- (void)createImg {
    self.placeHolderImg = [[UIImageView alloc] init];
    _placeHolderImg.frame = CGRectMake(SCREEN_WIDTH / 3, 100, SCREEN_WIDTH / 3, 140);
    _placeHolderImg.image = [UIImage imageNamed:@"searchmore@2x.png"];
    [self.view addSubview:_placeHolderImg];
    
    self.placeHolderLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 250, SCREEN_WIDTH, 50)];
    _placeHolderLabel.text = @"动动麒麟臂，搜更多内容";
    _placeHolderLabel.textAlignment = NSTextAlignmentCenter;
    _placeHolderLabel.textColor = [UIColor grayColor];
    [self.view addSubview:_placeHolderLabel];

}

/** 左上角返回按钮点击方法 */
- (void)backButtonAction:(UIBarButtonItem *) back {
    [self.navigationController popToRootViewControllerAnimated:YES];
    [_searchBar setHidden:YES];
    
}

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
    [self.searchBar resignFirstResponder];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
